// 优先队列,默认less大根堆: priority_queue<int> nVal; //3,2,1.
#include <functional>
#include <iostream>
#include <queue>
using namespace std;
struct Node {
  int priority;
  int value;
  bool operator<(const Node& other) const {
    return priority < other.priority;
  }  // less {1 2 6 8 9}
  bool operator>(const Node& other) const {
    return priority > other.priority;
  }  // greater {2 3 5 6 9}
};

int main() {
  const int len = 5;
  int i;
  int a[len] = {3, 5, 9, 6, 2};
  priority_queue<int> qInteger;  // 默认 {9 6 5 3 2}
  for (i = 0; i < len; i++) qInteger.push(a[i]);
  for (i = 0; i < len; i++) {
    cout << qInteger.top() << " ";
    qInteger.pop();
  }
  cout << endl;
  //示例2
  priority_queue<int, vector<int>, less<int> > qInteger2;  // {2 3 5 6 9}
  for (i = 0; i < len; i++) qInteger2.push(a[i]);
  for (i = 0; i < len; i++) {
    cout << qInteger2.top() << " ";
    qInteger2.pop();
  }
  cout << endl;
  //示例3
  // 默认需要 less operator<
  priority_queue<Node, vector<Node>, greater<Node> >
      qNode;  // 默认需要 greate operator>
  Node ndVal[len];
  ndVal[0].priority = 6;
  ndVal[0].value = 1;
  ndVal[1].priority = 9;
  ndVal[1].value = 5;
  ndVal[2].priority = 2;
  ndVal[2].value = 3;
  ndVal[3].priority = 8;
  ndVal[3].value = 2;
  ndVal[4].priority = 1;
  ndVal[4].value = 4;
  for (i = 0; i < len; i++) qNode.push(ndVal[i]);
  cout << "prior" << '\t' << "val" << endl;
  for (i = 0; i < len; i++) {
    auto [pri, val] = qNode.top();
    qNode.pop();
    cout << pri << '\t' << val << endl;
  }
  return 0;
}
